import React from 'react'
import { cateAdd } from '@/api/cake'
import { Button, Form, Input, Spin } from 'antd';
import { useRequest } from 'umi';
const layout = {
    labelCol: {
        span: 8,
    },
    wrapperCol: {
        span: 16,
    },
};
const tailLayout = {
    wrapperCol: {
        offset: 8,
        span: 16,
    },
};
const CatePub = () => {
    const [form] = Form.useForm();
    let { data, loading, run } = useRequest((value) => {
        console.log('aaa', value)
        return cateAdd(value)
    }, { manual: true });//开启手动执行
    const onFinish = (values) => {
        run(values)
        // console.log(values);
        // cateAdd(values).then(res => {
        //     console.log(res)
        // })
    };
    const onReset = () => {
        form.resetFields();
    };
    return (
        <Spin spinning={loading}>
            <Form {...layout} form={form} name="control-hooks" onFinish={onFinish}>
                <Form.Item
                    name="note"
                    label="蛋糕分类"
                    rules={[
                        {
                            required: true,
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    noStyle
                    shouldUpdate={(prevValues, currentValues) => prevValues.gender !== currentValues.gender}
                >
                    {({ getFieldValue }) =>
                        getFieldValue('gender') === 'other' ? (
                            <Form.Item
                                name="customizeGender"
                                label="Customize Gender"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Input />
                            </Form.Item>
                        ) : null
                    }
                </Form.Item>
                <Form.Item {...tailLayout}>
                    <Button type="primary" htmlType="submit">
                        Submit
                    </Button>
                    <Button htmlType="button" onClick={onReset}>
                        Reset
                    </Button>
                </Form.Item>
            </Form>
        </Spin>
    );
};
export default CatePub;

// export default function CatePub() {
//   return (
//     <div>catePub</div>
//   )
// }


